<?php

defined( '_JEXEC' ) or die( 'Restricted access' );

$ja_header_type = $params->get('ja_header_type');
$ja_header_imgtype = $params->get('ja_header_imgtype');
$ja_header_folder = $params->get('ja_header_folder');
$ja_header_timer = intval($params->get('ja_header_timer'));
$ja_header_order = $params->get('ja_header_order');
$ja_header_fadetime = intval($params->get('ja_header_fadetime'));
$ja_header_looping = $params->get('ja_header_looping');
$ja_header_xpos = intval($params->get('ja_header_xpos'));
$ja_header_ypos = intval($params->get('ja_header_ypos'));
$ja_header_width = $params->get('ja_header_width');
$ja_header_height = $params->get('ja_header_height');
switch ($ja_header_type) {
	case 'flash':
		//write to ja.headerxml.php file 
		$dir = $ja_header_folder;
		$ja_header_imgtype = explode (',', $ja_header_imgtype);
		for ($i=0;$i<count ($ja_header_imgtype); $i++) $ja_header_imgtype[$i] = "(\\.".$ja_header_imgtype[$i].")";

		$regex = '/'.@implode ('|', stripcslashes($ja_header_imgtype)).'$/i';
		$headerimage = "";

		$live_path = JURI::base().$dir;
		$abs_path = JPATH_SITE."/".$dir;
		$dh  = opendir($abs_path);
		$files = array();
		$write_string = "<gallery timer=\"".$ja_header_timer."\" order=\"".$ja_header_order."\" fadetime=\"".$ja_header_fadetime."\" looping=\"".$ja_header_looping."\" xpos=\"".$ja_header_xpos."\" ypos=\"".$ja_header_ypos."\">\n";
		
		while (false !== ($filename = readdir($dh))) {
			if (is_file($abs_path."/".$filename) && preg_match($regex, $filename)) {
				$write_string .= "<image path=\"$live_path/$filename\" />\n";
			}
		}
		$write_string .= "</gallery>";
		$fp=fopen(JPATH_SITE.'/modules/mod_ja_header/ja_header/ja.headerxml.php','w');
		fwrite($fp, $write_string) or die("Error writing to file");
		fclose($fp);
		//
		echo "<script type=\"text/javascript\" src=\"".JURI::base()."modules/mod_ja_header/ja_header/swfobject.js\"></script>\n";
		?>
		<div id="ja_header_flash">
		</div>
		<script type="text/javascript">
			var so = new SWFObject("<?php echo JURI::base(); ?>modules/mod_ja_header/ja_header/ja.header.swf", "ja_header_flash", "<?php echo $ja_header_width; ?>", "<?php echo $ja_header_height; ?>", "7", "#FFFFFF");
			so.addParam("wmode","transparent");
			so.addParam("flashvars","xml_input=<?php echo JURI::base(); ?>modules/mod_ja_header/ja_header/ja.headerxml.php");
			so.write("ja_header_flash");
		</script>
		
		<?php
		break;
	case 'js_fade':
		echo "<script type=\"text/javascript\" src=\"".JURI::base()."modules/mod_ja_header/ja_header/ja.header.js\"></script>\n";
		echo "<script type=\"text/javascript\">fadetime = ".($ja_header_fadetime*1000).";</script>";
		echo "<div id=\"ja_header_jsfade\" style=\"position:relative;width:$ja_header_width;height:$ja_header_height;overflow:hidden;;z-index:1;\">\n";

		$dir = $ja_header_folder;
		$ja_header_imgtype = explode (',', $ja_header_imgtype);
		for ($i=0;$i<count ($ja_header_imgtype); $i++) $ja_header_imgtype[$i] = "(\\.".$ja_header_imgtype[$i].")";

		$regex = '/'.@implode ('|', stripcslashes($ja_header_imgtype)).'$/i';
		$headerimage = "";

		$live_path = JURI::base().$dir;
		$abs_path = JPATH_SITE."/".$dir;
		$dh  = opendir($abs_path);
		$files = array();
		while (false !== ($filename = readdir($dh))) {
			if (is_file($abs_path."/".$filename) && preg_match($regex, $filename)) {
				echo "<img src=\"$live_path/$filename\" alt=\"\" title=\"\" style=\"position:absolute;top:0;left:0;display:none;z-index:1;\"/>\n";
			}
		}
		echo "</div>\n";
		break;
}



?>

